package com.bsc.rtc.lib.libraries;

import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.provider.Telephony;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.bsc.rtc.lib.libraries.BannerDemo.BannerDemoActivity;
import com.bsc.rtc.lib.libraries.CrashBreakPackage.ExceptionDemoActivity;
import com.bsc.rtc.lib.libraries.FloatView.FloatActivity;
import com.bsc.rtc.lib.libraries.FloatView.FloatService;
import com.bsc.rtc.lib.libraries.GilideDemo.GlideDemoActivity;
import com.bsc.rtc.lib.libraries.IjkPlayer.IjkDemoActivity;
import com.bsc.rtc.lib.libraries.MsgDispatchDemo.DisPatchDemoActivity;
import com.bsc.rtc.lib.libraries.MyViewDemo.ScrollActivity;
import com.bsc.rtc.lib.libraries.MyViewDemo.View.CloudTestActivity;
import com.bsc.rtc.lib.libraries.RecycleViewBase.CommonAdapter;
import com.bsc.rtc.lib.libraries.RecycleViewBase.RecyclerDemoActivity;
import com.bsc.rtc.lib.libraries.RecycleViewBase.base.ViewHolder;
import com.bsc.rtc.lib.libraries.RetrofitNet.DownUpLoadActivity;
import com.bsc.rtc.lib.libraries.RxJavaRetrofitDemo.RetrofitActivity;
import com.bsc.rtc.lib.libraries.RxJavaRetrofitDemo.RxDemoActivity;
import com.bsc.rtc.lib.libraries.RxJavaRetrofitDemo.RxPermissionDemoActivity;
import com.bsc.rtc.lib.libraries.UsharedDemo.USharedDemoActivity;
import com.bsc.rtc.lib.libraries.Video.AudioActivity;
import com.bsc.rtc.lib.libraries.Video.MediaActivity;
import com.bsc.rtc.lib.libraries.WebViewDemos.MWebViewActivity;
import com.bsc.rtc.lib.libraries.ZxingDemo.ZxingDemoActivity;
import com.bsc.rtc.lib.libraries.apkinstall.ApkInstallTActivity;
import com.bsc.rtc.lib.libraries.behavior.sampleTitleBehavior.BehaviorActivity;
import com.bsc.rtc.lib.libraries.dagger.DaggerDemoActivity;
import com.bsc.rtc.lib.libraries.materialdesign.MaiterialDesignActivity;
import com.bsc.rtc.lib.libraries.statefulllayout.StateDemoActivity;
import com.bsc.rtc.lib.libraries.titleUtils.TitleDemoActivity;
import com.bsc.rtc.lib.libraries.utils.SnackbarActivity;
import com.bsc.rtc.lib.libraries.wedgit.ViewShowActivity;
import com.tencent.bugly.crashreport.CrashReport;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import static android.net.Uri.withAppendedPath;

public class MainActivity extends AppCompatActivity {
    RecyclerView homeRecycler;
    CommonAdapter<HomeEntity> homeAdapter;
    List<HomeEntity> homeList = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
    }
    /*private void getAllApns() {
        final Uri APN_TABLE_URI = Uri.parse("content://telephony/carriers");
        final Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn");
        final Uri CURRENT_APN_URI = Uri.parse("content://telephony/carriers/current");
        Cursor cr = this.getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);
        String[] mStrings = new String[cr.getCount()];
        int i = 0;
        while (cr != null && cr.moveToNext()) {
            Log.i("zzw","apns="+"ID:" + cr.getString(cr.getColumnIndex("_id"))+" "+"authtype:" + cr.getString(cr.getColumnIndex("authtype")));
            mStrings[i] = "ID:" + cr.getString(cr.getColumnIndex("_id")) +
                    "\n" + "name:" + cr.getString(cr.getColumnIndex("name")) +
                    "\n" + "numeric:" + cr.getString(cr.getColumnIndex("numeric")) +
                    "\n" + "mcc:" + cr.getString(cr.getColumnIndex("mcc")) +
                    "\n" + "mnc:" + cr.getString(cr.getColumnIndex("mnc")) +
                    "\n" + "apn:" + cr.getString(cr.getColumnIndex("apn")) +
                    "\n" + "user:" + cr.getString(cr.getColumnIndex("user")) +
                    "\n" + "server:" + cr.getString(cr.getColumnIndex("server")) +
                    "\n" + "password:" + cr.getString(cr.getColumnIndex("password")) +
                    "\n" + "proxy:" + cr.getString(cr.getColumnIndex("proxy")) +
                    "\n" + "port:" + cr.getString(cr.getColumnIndex("port")) +
                    "\n" + "mmsproxy:" + cr.getString(cr.getColumnIndex("mmsproxy")) +
                    "\n" + "mmsport:" + cr.getString(cr.getColumnIndex("mmsport")) +
                    "\n" + "mmsc:" + cr.getString(cr.getColumnIndex("mmsc")) +
                    "\n" + "authtype:" + cr.getString(cr.getColumnIndex("authtype")) +
                    "\n" + "type:" + cr.getString(cr.getColumnIndex("type")) +
                    "\n" + "current:" + cr.getString(cr.getColumnIndex("current"));

            i++;
        }

    }*/

    static class HomeEntity {
        String name;
        Class className;

        public HomeEntity(String name, Class className) {
            this.name = name;
            this.className = className;
        }
    }

    private void initView() {
        homeRecycler = findViewById(R.id.home_recycler);
        homeAdapter = new CommonAdapter<HomeEntity>(this, R.layout.item_home_layout, homeList) {
            @Override
            protected void convert(ViewHolder holder, HomeEntity homeEntity, int position) {
                holder.setText(R.id.home_item_tv, homeEntity.name);
                holder.itemView.setOnClickListener(new HomeOnclickListener(position));
            }


        };
        homeRecycler.setLayoutManager(new LinearLayoutManager(this));
        homeRecycler.setAdapter(homeAdapter);
    }

    class HomeOnclickListener implements View.OnClickListener {
        int currentPosition = 0;

        public HomeOnclickListener(int currentPosition) {
            this.currentPosition = currentPosition;
        }

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, homeList.get(currentPosition).className);
            startActivity(intent);
        }
    }

    private void initData() {
        homeList.add(new HomeEntity("FloatActivity", FloatActivity.class));
        homeList.add(new HomeEntity("ZxingDemoActivity", ZxingDemoActivity.class));
        homeList.add(new HomeEntity("USharedDemoActivity", USharedDemoActivity.class));
        homeList.add(new HomeEntity("IjkDemoActivity", IjkDemoActivity.class));
        homeList.add(new HomeEntity("ExceptionDemoActivity", ExceptionDemoActivity.class));
        homeList.add(new HomeEntity("MediaActivity", MediaActivity.class));
        homeList.add(new HomeEntity("AudioActivity", AudioActivity.class));
        homeList.add(new HomeEntity("RxDemoActivity", RxDemoActivity.class));
        homeList.add(new HomeEntity("RetrofitActivity", RetrofitActivity.class));
        homeList.add(new HomeEntity("MWebViewActivity", MWebViewActivity.class));
        homeList.add(new HomeEntity("BannerDemoActivity", BannerDemoActivity.class));
        homeList.add(new HomeEntity("TitleDemoActivity", TitleDemoActivity.class));
        homeList.add(new HomeEntity("SnackbarActivity", SnackbarActivity.class));
        homeList.add(new HomeEntity("StateDemoActivity", StateDemoActivity.class));
        homeList.add(new HomeEntity("DisPatchDemoActivity", DisPatchDemoActivity.class));
        homeList.add(new HomeEntity("ScrollActivity", ScrollActivity.class));
        homeList.add(new HomeEntity("BehaviorActivity", BehaviorActivity.class));
        homeList.add(new HomeEntity("RecyclerDemoActivity", RecyclerDemoActivity.class));
        homeList.add(new HomeEntity("DownUpLoadActivity", DownUpLoadActivity.class));
        homeList.add(new HomeEntity("ViewShowActivity", ViewShowActivity.class));
        homeList.add(new HomeEntity("CloudTestActivity", CloudTestActivity.class));
        homeList.add(new HomeEntity("TestDemoActivity", TestDemoActivity.class));
        homeList.add(new HomeEntity("ApkInstallTActivity", ApkInstallTActivity.class));
        homeList.add(new HomeEntity("MaiterialDesignActivity", MaiterialDesignActivity.class));
        homeList.add(new HomeEntity("DaggerDemoActivity", DaggerDemoActivity.class));
        homeList.add(new HomeEntity("GlideDemoActivity", GlideDemoActivity.class));
        homeList.add(new HomeEntity("RxPermissionDemoActivity", RxPermissionDemoActivity.class));
        homeList.add(new HomeEntity("RSAActivity", RSAActivity.class));

        homeAdapter.notifyDataSetChanged();
    }

    //开启Activity悬浮窗
    private void startFloatActivity() {
        if (Build.VERSION.SDK_INT >= 23) {
            if (Settings.canDrawOverlays(MainActivity.this)) {
                Intent intent = new Intent(MainActivity.this, FloatActivity.class);
                Toast.makeText(MainActivity.this, "已开启Toucher", Toast.LENGTH_SHORT).show();
                startActivity(intent);
                //finish();
            } else {
                //若没有权限，提示获取.
                Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
                Toast.makeText(MainActivity.this, "需要取得权限以使用悬浮窗", Toast.LENGTH_SHORT).show();
                startActivity(intent);
            }
        } else {
            //SDK在23以下，不用管.
            Intent intent = new Intent(MainActivity.this, FloatActivity.class);
            startActivity(intent);
            //finish();
        }
    }

    //开启Service悬浮窗
    private void startService() {
        if (Build.VERSION.SDK_INT >= 23) {
            if (Settings.canDrawOverlays(MainActivity.this)) {
                Intent intent = new Intent(MainActivity.this, FloatService.class);
                Toast.makeText(MainActivity.this, "已开启Toucher", Toast.LENGTH_SHORT).show();
                startService(intent);
                finish();
            } else {
                //若没有权限，提示获取.
                Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
                Toast.makeText(MainActivity.this, "需要取得权限以使用悬浮窗", Toast.LENGTH_SHORT).show();
                startActivity(intent);
            }
        } else {
            //SDK在23以下，不用管.
            Intent intent = new Intent(MainActivity.this, FloatService.class);
            startService(intent);
            finish();
        }
    }



}

